@extends('layout.adminlayout')
@section('css')
<script src="/admin/js/metisMenu.min.js"></script>
<script src="/admin/js/custom.js"></script>
<link href="/admin/css/area_info.css" rel="stylesheet">
<link href="/admin/css/custom.css" rel="stylesheet">
<link href="/admin/css/add_manage.css" rel="stylesheet">
<script type="text/javascript" src="http://api.map.baidu.com/getscript?v=2.0&ak=U25vSd26q851cuSCjMCXuFkYYemWxvRs&services=&t=20170707103901"></script>
@endsection
@section('content')
<div class="forms">
	<div class=" form-grids row form-grids-right">
		<div class="widget-shadow " data-example-id="basic-forms"> 
			<div class="form-title">
				<h4>建筑编辑 :</h4>
			</div>
			<div class="form-body">
				<form action="/admin/building/store" method="post" class="form-horizontal" onsubmit="return fun4()" style="position:relative">
					{{csrf_field()}}
					<div class="form-group">
						<label for="inputEmail3" class="col-sm-1 control-label">
							所属地区 :
						</label>
						<li class="area_info">
							<div class="col-sm-6">
								<select name="area" id="area" class="form-control1">
									<option value="0">请选择区域</option>
									@if($area != null)
										@foreach($area as $v)
											<option value="{{$v['a_id']}}"
												@if($v['a_id'] == $data['a_id'])
													selected
												@endif
											>{{$v['a_name']}}</option>
										@endforeach
									@endif
								</select>
							</div>
						</li>
					</div>
					<div class="form-group">
						<label for="inputPassword3" class="col-sm-1 control-label">
							建筑名称 :
						</label>
						<div class="col-sm-6">
							<input type="hidden" id="b_id" value="{{$data['b_id']}}">
							<input type="text" class="form-control" name="building" id="building" placeholder="建筑名称" value="{{$data['b_name']}}">
						</div>
					</div>
					<div class="form-group">
						<label for="inputPassword3" class="col-sm-1 control-label">
							总层数 :
						</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" name="total" id="total" placeholder="总层数" value="{{$data['b_total_floor']}}">
						</div>
					</div>
					<div class="form-group">
						<label for="inputPassword3" class="col-sm-1 control-label">
							最低层 :
						</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" name="low" id="low" placeholder="最底层数" value="{{$data['b_low_floor']}}">
						</div>
					</div>
					<div class="form-group">
						<label for="inputPassword3" class="col-sm-1 control-label">
							最高层 :
						</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" name="high" id="high" placeholder="最高层数" value="{{$data['b_high_floor']}}">
						</div>
					</div>
					<div class="form-group">
						<label for="inputPassword3" class="col-sm-1 control-label">
							经度 :
						</label>
						<div class="col-sm-6" id="longitude">
							<input type="text" class="form-control" name="long" placeholder="113.381500" value="{{$data['b_longitude']}}"  readonly>
						</div>
					</div>
					<div class="form-group">
						<label for="inputPassword3" class="col-sm-1 control-label">
							纬度 :
						</label>
						<div class="col-sm-6" id="latitude">
							<input type="text" class="form-control" name="lat" placeholder="34.435400" value="{{$data['b_latitude']}}"  readonly>
						</div>
					</div>
					<div class="form-group">
						<label for="inputPassword3" class="col-sm-1 control-label">
							负责人 :
						</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" name="manage" placeholder="管理员名称" id="manage" style="width: 80%; float: left">
							<button type="button" class="btn btn-default" id="add" style="float: right">添加</button>
						</div>
					</div>
					<div class="form-group">
						<label for="inputPassword3" class="col-sm-1 control-label">
						</label>
						<div class="col-sm-6" id="latitude">
							<ul id="ul" style="border:0px; width:100%; padding:0px; background:none; height:34px;">
								@foreach($data['mma_username'] as $v)
									<li><div class="a">&nbsp;<span class="mng">{{$v}}</span>&nbsp;<img src="/admin/images/error1.png" alt="" class="img">&nbsp;</div></li>
								@endforeach
							</ul>
						</div>
					</div>
					<div id='allmap' style="width: 40%; height: 100%; position: absolute; top: 0px; right: 0px;">
					</div>
					<div class="col-sm-offset-2">
						<button type="button" class="btn btn-default" id="sub">提交</button>
					</div>
				</form> 
			</div>
		</div>
	</div>
</div>
<script>
    //提交表单
    $('#sub').click(function () {
        var b_id = $('#b_id').val();
        var area = $('#area').val();
        var building = $('#building').val();
        var total = $('#total').val();
        var low = $('#low').val();
        var high = $('#high').val();
		//处理后的经度纬度
        var longitude = $('input[name=long]').val();
        var lat = $('input[name=lat]').val();
        var manage = new Array();
        $('.mng').each(function () {
            manage.push($(this).html());
        });
        if(area != 0 && building !='' && total != '' && low != '' && high != ''){
            $.ajax({
                type:'post',
                url:'/admin/building/edit',
                async:false,
                data:{
                    "_token": $("input[name=_token]").val(),
					'b_id':b_id,
                    'area':area,
					'building':building,
					'total':total,
					'low':low,
					'high':high,
					'long':longitude,
					'lat':lat,
                    'manage':manage
                },
                dataType:'json',
                success:function (data) {
                    location.href = '/admin/building/index';
                }
            })
        }else{
            alert('信息填写不完整或经纬度填写不合法')
            return false;
        }
    });
</script>
@endsection
@section('lastjs')
<script src="/admin/js/add_manage.js"></script>
<script src="/admin/js/map_new.js"></script>
@endsection